package l1j.server.server.model.damage.hit;

import l1j.server.server.model.Instance.L1NpcInstance;
import l1j.server.server.model.Instance.L1PetInstance;
import l1j.server.server.model.Instance.L1SummonInstance;
import l1j.server.server.utils.Random;

public class L1Hit_Npc_Npc extends L1Hit{
	private L1NpcInstance _attacker;

	private L1NpcInstance _target;
	private L1NpcHit _npcHit;

	public L1Hit_Npc_Npc(L1NpcInstance attacker, L1NpcInstance target) {
		_attacker = attacker;
		_target = target;
		_npcHit = new L1NpcHit(attacker,target);
	}
	public boolean calcHit(){
		_npcHit.doAttackAction();
		if (_target.isInvincible())
			return false;
		calcNpcNpcHit();
		return _isHit;
	}
	
	private void calcNpcNpcHit(){
		_hitRate = _npcHit.calcNpcHitRate(_hitRate);

		L1OnNpcHit oph = new L1OnNpcHit(_target);
		_hitRate = oph.hitRateOnNpc(_hitRate);

		_isHit = Random.chance100(_hitRate);
		
		if (((_attacker instanceof L1PetInstance) || (_attacker instanceof L1SummonInstance))
				&& ((_target instanceof L1PetInstance) || (_target instanceof L1SummonInstance))) {
			// 目標在安區、攻擊者在安區、NOPVP
			if ((_target.getZoneType() == 1) || (_attacker.getZoneType() == 1)) {
				_hitRate = 0;
			}
		}
	}

}
